# -*- mode: org; fill-column: 80; -*-
#+TITLE: Comparison
#+AUTHOR: Zelphir Kaltstahl
#+STARTUP: content indent align inlineimages entitiesplain nologdone nologreschedule nologredeadline nologrefile
#+TODO: TODO WIP | DONE
#+DATE: <2021-05-08 Sa>
#+LANGUAGE: English
#+PRIORITIES: A C C

* General information

Reals cannot be compared using:

- ~=~
- ~<>~

This is because calculations with IEEE754 floats can have imprecise results and
different results depending on the order of operation, which would not matter
for truly real numbers. To protect the programmer from calculation mistakes when
dealing with IEEE754 floats, these comparisons are forbidden to be used on
reals.

* Number comparisons

#+begin_src sml :results output drawer replace verbatim
1 = 1;
2 > 1;
1 < 2;
2 <> 1;
2 >= 1;
1 <= 2;
1.0 = 1.0;
1.0 <> 2.0; (*error*)
1.0 <= 2.0; (*error*)
#+end_src

#+RESULTS:
:results:
val it = true : bool
:end:

* String comparisons

(lexicographic ordering)

#+begin_src sml :results output drawer replace verbatim
"abc" < "def";
"abc" <= "def";
"abc" > "def";
"abc" >= "def";
"abc" <> "def";
"abc" = "def";
#+end_src

#+RESULTS:
:results:
val it = true : bool
:end:

* Character comparisons

(lexicographically precedes)

#+begin_src sml :results output drawer replace verbatim
#"a" < #"b";
#"a" <= #"b";
#"a" > #"b";
#"a" >= #"b";
#"a" <> #"b";
#"a" = #"b";
#+end_src

#+RESULTS:
:results:
val it = true : bool
:end:
